package com.example.busbus.controller;

import com.example.busbus.entity.BusLine;
import com.example.busbus.service.BusLineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bus")
public class BusLineController {

    @Autowired
    private BusLineService busLineService;

    @GetMapping("/lines")
    public List<BusLine> getAllBusLines() {
        return busLineService.getAllBusLines();
    }

    @GetMapping("/line/{id}")
    public BusLine getBusLineById(@PathVariable Long id) {
        return busLineService.getBusLineById(id);
    }

    @PostMapping("/line")
    public void addBusLine(@RequestBody BusLine busLine) {
        busLineService.addBusLine(busLine);
    }

    @PutMapping("/line")
    public void updateBusLine(@RequestBody BusLine busLine) {
        busLineService.updateBusLine(busLine);
    }

    @DeleteMapping("/line/{id}")
    public void deleteBusLine(@PathVariable Long id) {
        busLineService.deleteBusLine(id);
    }

    @GetMapping("/search/name")
    public List<BusLine> searchByName(@RequestParam String name) {
        return busLineService.searchByName(name);
    }

    @GetMapping("/search/number")
    public List<BusLine> searchByLineNumber(@RequestParam String lineNumber) {
        return busLineService.searchByLineNumber(lineNumber);
    }
}